package ModelLayer;
import java.util.ArrayList;
import java.util.Arrays;

/**
 * Vestbjerg project
 * @GroupB2 (UCN - Computer Science DMAJ0914) 
 */

public class EmployeeContainer
{
    //instance variables
    private static EmployeeContainer instance;
    private ArrayList<Employee> employeeList;

    /**
     * Constructor for objects of class EmployeeContainer
     */
    private EmployeeContainer()
    {
        employeeList = new ArrayList<Employee>();
    }

    public static EmployeeContainer getInstance() 
    {
        if(instance == null) 
        {
            instance = new EmployeeContainer();
        }
        return instance;
    }

    public void addEmployee(Employee employee) 
    {
        employeeList.add(employee);
    }

    public Employee findEmployee(String id) 
    {
        Employee returnEmployee = null;
        for(Employee employee : employeeList) 
        {

            if(id.equals(employee.getId())) 
            {
                returnEmployee = employee;
            }
        }
        return returnEmployee;
    }

    public void deleteEmployee(Employee employee) 
    {
        if(employeeList.contains(employee)) 
        {
            employeeList.remove(employee);
        }
    }

    public ArrayList<String> employeeSort()
    {
        ArrayList<String> sortedEmployeeList = new ArrayList<String>();
        IFPerson[] employeeArr = new IFPerson[employeeList.size()];

        employeeList.toArray(employeeArr);
        Arrays.sort(employeeArr);

        for(IFPerson employee : employeeArr)
        {
            sortedEmployeeList.add(employee.getId());
        }

        return sortedEmployeeList;
    }

    public ArrayList<Employee> getEmployeeList() 
    {
        return employeeList;
    }
}